/*
 * Copyright (c) 2018 Tencent. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
const AbstractModel = require("../../common/abstract_model");

/**
 * ImageToImage request structure.
 * @class
 */
class ImageToImageRequest extends  AbstractModel {
    constructor(){
        super();

        /**
         * Base64 code of the input mage.
Either the Base64 code or URL must be provided. If both are provided, URL prevails.
Image restrictions: The single-edge resolution must be less than 5,000 and greater than 50, and the size after Base64 encoding must be less than 8 MB. Supported formats include JPG, JPEG, PNG, BMP, TIFF and WEBP.
         * @type {string || null}
         */
        this.InputImage = null;

        /**
         * URL of the input mage.
Either the Base64 code or URL must be provided. If both are provided, URL prevails.
Image restrictions: The single-edge resolution must be less than 5,000 and greater than 50, and the size after Base64 encoding must be less than 8 MB. Supported formats include JPG, JPEG, PNG, BMP, TIFF and WEBP.
         * @type {string || null}
         */
        this.InputUrl = null;

        /**
         * Text description.
It is used to increase the possibility that the generation result contains the described content.
A maximum of 256 UTF-8 characters are supported.
         * @type {string || null}
         */
        this.Prompt = null;

        /**
         * Negative text description.
It is used to reduce the possibility that the generation result contains the described content, but such content cannot be completely avoided.
English is recommended. A maximum of 256 UTF-8 characters are supported.
         * @type {string || null}
         */
        this.NegativePrompt = null;

        /**
         * Image style.
Select the desired style from the [Image Style List](https://intl.cloud.tencent.com/document/product/1668/86250?from_cn_redirect=1) and enter the style number.
It is recommended to use only one style. If no style is specified, 201 (anime style) is used by default.
         * @type {Array.<string> || null}
         */
        this.Styles = null;

        /**
         * Configurations of the generated image, including the resolution.
Images with the following resolutions can be generated: origin (The resolution is the same as the input image resolution, with the edge resolution of up to 2000. The image will be zoomed out proportionally if the resolution is exceeded.), 768:768 (1:1), 768:1024 (3:4), and 1024:768 (4:3).
If the resolution is not specified, origin is used by default.
         * @type {ResultConfig || null}
         */
        this.ResultConfig = null;

        /**
         * Switch indicating whether to add a logo to the generated image. Default value: 1.
1: add logo
0: do not add logo
Other values: add logo
It is recommended to use an obvious logo to indicate that the image result is generated by AI.
         * @type {number || null}
         */
        this.LogoAdd = null;

        /**
         * Logo content settings.
By default, the text "Generated by AI" is added to the bottom right corner of the generated image. You can also use other logo.
         * @type {LogoParam || null}
         */
        this.LogoParam = null;

        /**
         * Generation strength.
The smaller the strength value, the more the generated image resembles the original image. Value range: (0, 1]. If the strength is not specified, the default value of the model is used.
The recommended value range is 0.6 to 0.8.
         * @type {number || null}
         */
        this.Strength = null;

        /**
         * Image return method (base64 or url).
You can specify only one method. Default value: base64.
The URL is valid for 1 hour.
         * @type {string || null}
         */
        this.RspImgType = null;

        /**
         * Switch indicating whether to  enhance image clarity. Default value: 0.
1: on
0: off
If the switch is turned on, the image clarity will be enhanced and the generation time will increase.
         * @type {number || null}
         */
        this.EnhanceImage = null;

        /**
         * Maximum number of faces for detail restoration. Value range: 0 - 6. Default value: 0.
If the input value is greater than 0, the value will be used as the maximum number of faces with a small area can be restored in each image. The generation time will increase according to the actual number of faces restored.
         * @type {number || null}
         */
        this.RestoreFace = null;

    }

    /**
     * @private
     */
    deserialize(params) {
        if (!params) {
            return;
        }
        this.InputImage = 'InputImage' in params ? params.InputImage : null;
        this.InputUrl = 'InputUrl' in params ? params.InputUrl : null;
        this.Prompt = 'Prompt' in params ? params.Prompt : null;
        this.NegativePrompt = 'NegativePrompt' in params ? params.NegativePrompt : null;
        this.Styles = 'Styles' in params ? params.Styles : null;

        if (params.ResultConfig) {
            let obj = new ResultConfig();
            obj.deserialize(params.ResultConfig)
            this.ResultConfig = obj;
        }
        this.LogoAdd = 'LogoAdd' in params ? params.LogoAdd : null;

        if (params.LogoParam) {
            let obj = new LogoParam();
            obj.deserialize(params.LogoParam)
            this.LogoParam = obj;
        }
        this.Strength = 'Strength' in params ? params.Strength : null;
        this.RspImgType = 'RspImgType' in params ? params.RspImgType : null;
        this.EnhanceImage = 'EnhanceImage' in params ? params.EnhanceImage : null;
        this.RestoreFace = 'RestoreFace' in params ? params.RestoreFace : null;

    }
}

/**
 * ImageToImage response structure.
 * @class
 */
class ImageToImageResponse extends  AbstractModel {
    constructor(){
        super();

        /**
         * Different content is returned depending on the input parameter RspImgType.
If the value is base64, the Base64 code of the generated image is returned.
If the value is url, the URL of the generated image is returned. The URL is valid for 1 hour. Save it in time.
         * @type {string || null}
         */
        this.ResultImage = null;

        /**
         * The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.
         * @type {string || null}
         */
        this.RequestId = null;

    }

    /**
     * @private
     */
    deserialize(params) {
        if (!params) {
            return;
        }
        this.ResultImage = 'ResultImage' in params ? params.ResultImage : null;
        this.RequestId = 'RequestId' in params ? params.RequestId : null;

    }
}

/**
 * Input box
 * @class
 */
class LogoRect extends  AbstractModel {
    constructor(){
        super();

        /**
         * X-axis coordinate of the upper left corner
         * @type {number || null}
         */
        this.X = null;

        /**
         * Y-axis coordinate of the upper left corner
         * @type {number || null}
         */
        this.Y = null;

        /**
         * Box width
         * @type {number || null}
         */
        this.Width = null;

        /**
         * Box height
         * @type {number || null}
         */
        this.Height = null;

    }

    /**
     * @private
     */
    deserialize(params) {
        if (!params) {
            return;
        }
        this.X = 'X' in params ? params.X : null;
        this.Y = 'Y' in params ? params.Y : null;
        this.Width = 'Width' in params ? params.Width : null;
        this.Height = 'Height' in params ? params.Height : null;

    }
}

/**
 * Logo parameter
 * @class
 */
class LogoParam extends  AbstractModel {
    constructor(){
        super();

        /**
         * Logo URL
         * @type {string || null}
         */
        this.LogoUrl = null;

        /**
         * Logo Base64 code. Either the Base64 code or URL must be provided. If both are provided, URL prevails.
         * @type {string || null}
         */
        this.LogoImage = null;

        /**
         * Coordinates of the logo image in the generated image. The logo image will be stretched according to the coordinates.
         * @type {LogoRect || null}
         */
        this.LogoRect = null;

    }

    /**
     * @private
     */
    deserialize(params) {
        if (!params) {
            return;
        }
        this.LogoUrl = 'LogoUrl' in params ? params.LogoUrl : null;
        this.LogoImage = 'LogoImage' in params ? params.LogoImage : null;

        if (params.LogoRect) {
            let obj = new LogoRect();
            obj.deserialize(params.LogoRect)
            this.LogoRect = obj;
        }

    }
}

/**
 * Return result configurations
 * @class
 */
class ResultConfig extends  AbstractModel {
    constructor(){
        super();

        /**
         * Generated image resolution.

Images with the following resolutions can be generated: origin (The resolution is the same as the input image resolution, with the edge resolution of up to 2000. The image will be zoomed out proportionally if the resolution is exceeded.), 768:768 (1:1), 768:1024 (3:4), and 1024:768 (4:3). If the resolution is not specified, origin is used by default. The generated image may be cropped if the aspect ratio of the generated image is too different from that of the input image.
         * @type {string || null}
         */
        this.Resolution = null;

    }

    /**
     * @private
     */
    deserialize(params) {
        if (!params) {
            return;
        }
        this.Resolution = 'Resolution' in params ? params.Resolution : null;

    }
}

module.exports = {
    ImageToImageRequest: ImageToImageRequest,
    ImageToImageResponse: ImageToImageResponse,
    LogoRect: LogoRect,
    LogoParam: LogoParam,
    ResultConfig: ResultConfig,

}
